package com.qf.service.impl;

import com.qf.api.CacheFeign;
import com.qf.constant.CacheConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.StrategyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Map;

/**
 * 黑名单策略
 * @Author ztf
 * @Date 19:45 2021/11/24
 **/
@Service(value = "black")
@Slf4j
public class BlackServiceImpl implements StrategyService {

    @Autowired
    private CacheFeign cacheFeign;


    /**
     * 策略方法
     *
     * @param standardSubmit
     * @return
     */
    @Override
    public boolean execute(StandardSubmit standardSubmit) {
        log.info("【策略模块-黑名单策略】启动，短信对象内容为：standardSubmit={}",standardSubmit);

        //1. 获取黑名单
        String value =  cacheFeign.get(CacheConstants.CACHE_PREFIX_BLACK+standardSubmit.getDestMobile());

        if (StringUtils.isEmpty(value)){
            log.info("【策略模块-黑名单策略】当前号码不在黑名单中");
            return true;
        }else {
            log.info("【策略模块-黑名单策略】当前号码在黑名单中,发送失败");
            return false;
        }
    }
}
